package com.four.bmm.controller;

import com.four.bmm.entity.Block;
import com.four.bmm.entity.BlockItem;
import com.four.bmm.service.BlockService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@WebServlet("/BlockServlet")
public class BlockServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        BlockService blockService=new BlockService();
        List<Block> blocks= blockService.findAllBlock();
        int bCount=blockService.calBlockCount();
        List<BlockItem> blockItems=blockService.findAllBItem();
        int biCount=blockService.calBlockItemCount();
        HttpSession session=request.getSession();
        request.setAttribute("bCount",bCount);
        session.setAttribute("biCount",biCount);
        request.setAttribute("blocks",blocks);
        session.setAttribute("blocks",blocks);
        request.setAttribute("blockItems",blockItems);
        session.setAttribute("blockItems",blockItems);
        request.getRequestDispatcher("back/block-list.jsp").forward(request,response);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
